package ik;

import org.wltea.analyzer.core.IKSegmenter;
import org.wltea.analyzer.core.Lexeme;

import java.io.IOException;
import java.io.StringReader;
import java.util.*;

/**
 * 敏感词处理工具 - IKAnalyzer中文分词工具 - 借助分词进行敏感词过滤
 *
 * @author sam
 * @since 2017/9/4
 */
public class SensitiveWordUtil2 {
    /**
     * 对语句进行分词
     *
     * @param text 语句
     * @return 分词后的集合
     * @throws IOException
     */
    private static List segment(String text) throws IOException {
        List<String> list = new ArrayList<>();
        StringReader re = new StringReader(text);
        IKSegmenter ik = new IKSegmenter(re, true);
        Lexeme lex;
        while ((lex = ik.next()) != null) {
            String word=lex.getLexemeText();
            if(!"项目".equals(word)
            &&!"发电".equals(word)){
                list.add(word);
            }

        }
        return list;
    }


    public static void main(String[] args) throws IOException {

        List textList=segment("华能榆社西马100MW光伏发电项目");
        System.out.println(textList);
    }

}

